<?PHP
$media=new music;



if(!empty($_GET['id']) && !empty($_GET['songid']) && $_GET['cmd']=='add')
{
	$media->post=$_GET;
	$media->add_song_to_playlist();
	printmessage('adding song');
}
else if (!empty($_GET['id']) && !empty($_GET['songid']) && $_GET['cmd']=='delete')
{
	$media->post=$_GET;
	printmessage('removing song');
	$media->remove_song_from_playlist();
	
}
if(!empty($_GET['id']))
{	
	$media->post=$_GET;
	$playlist=$media->get_songs_for_playlist();
}
$media->where['type']='song';
if(!empty($_GET['letter']))
{
	
	if($_GET['letter']=='all')
	{
		$media->options['letter']=NULL;
	}
	else
	{
	$media->options['letter']=$_GET['letter'];	
	}
}
else
{
$media->options['letter']='a';	
}
$media->get_music();

//$pager=new paginator;
//$pager->data=$media->data;
//$pager->items=500;
//$pager->paginate();
//$pager->print_pager();
?>
<script type="text/javascript"> 
// When the document is ready set up our sortable with it's inherant function(s) 
$(document).ready(function() { 
  $("#test-list").sortable({ 
    handle : '.handle', 
    update : function () { 
		$("#info").text('Processing');
      var order = $('#test-list').sortable('serialize'); 
      $("#info").load("m/music/a_sort_music.php?"+order+"&playlist=<?PHP echo $_GET['id']?>"); 
    } 
  }); 

$('#song_table tbody tr').quicksearch({ position: 'before', attached: '#song_table',stripeRowClass: ['even', ''],labelText: 'Find'});
$('#media_table tbody tr').quicksearch({ position: 'before', attached: '#media_table',stripeRowClass: ['even', ''],labelText: 'Find'});
}); 
</script>


	<div class="formholder">
	<div class="datatop">

	Your Playlist
	</div>
	<div class="datalabel" id="info">Move around to update</div>
	<div class="datadata">
<table id="media_table" class="tablesorter song_playlist" cellspacing="0"><tbody id="test-list" style='clear:both;'> 


				
<?PHP

foreach($playlist as $x)
{
	?>
	<tr id="listItem_<?PHP echo $x['id'];?>"> 
  <td><?PHP echo $x['order'];?> </td>
    <td><?PHP echo $x['name'];?> </td>
	<td><?PHP echo $x['artist'];?></td>
	<td><?PHP echo $x['album'];?></td>
	<td><?PHP echo $x['genre'];?></td>

	<td><a href="?q=m/music/d_playlist_manager.php&cmd=delete&id=<?PHP echo $_GET['id'];?>&songid=<?PHP echo $x['id'];?>">Delete</a></td>
	<td class='handle'>Move</td>
  	</tr>
	<?
	
}
?>
</tbody> </table>


<form action="process-sortable.php" method="post" name="sortables"> 
  <input type="hidden" name="test-log" id="test-log" /> 
</form>

</div><div class="datafootbg"></div></div>

<div id='results'></div>





	<div class="formholder">
	<div class="datatop">

	Music Library
	</div>
	<div class="datalabel">Move around to update</div>
	<div class="datadata">
<table id="song_table" class="tablesorter song_playlist" cellspacing="0"><tbody style='clear:both;'> 


				
<?PHP

foreach($media->data as $x)
{
	?>
	<tr> 

    <td class='p_name'><?PHP echo $x['name'];?> </td>
	<td class='p_artist'><?PHP echo $x['artist'];?></td>
	<td class='p_album'><?PHP echo $x['album'];?></td>
	<td class='p_genre'><?PHP echo $x['genre'];?></td>
	<td>p <?PHP echo $x['play'];?></td>
	<td>r <?PHP echo $x['request'];?></td>
	<td><a href='?q=m/music/a_add_music.php&cmd=add&id=<?PHP echo $x['id'];?>' class='add_music' name='<?PHP echo $x['id'];?>/<?PHP echo $_GET['id'];?>/<?PHP echo $x['name'];?>/<?PHP echo $x['artist'];?>/<?PHP echo $x['album'];?>/<?PHP echo $x['genre'];?>'>Add</a></td>
  	</tr>
	<?
	
}
?>
</tbody> </table>



<form action="process-sortable.php" method="post" name="sortables"> 
  <input type="hidden" name="test-log" id="test-log" /> 
</form>



<ul class='paginator'>
	<?PHP
	
	//$pager[$i]='http://'.$_SERVER['HTTP_HOST'].$script_name.$queries.'&page='.$i;
	?>
	<?php
	foreach(range('a', 'z') as $letter) {
		$queries=get_clean_queries();
		$script_name=$_SERVER['SCRIPT_NAME'];
		$link='http://'.$_SERVER['HTTP_HOST'].$script_name.$queries.'&letter='.$letter;
		$all='http://'.$_SERVER['HTTP_HOST'].$script_name.$queries.'&letter=all';
	   ?>
		<li> <a href='<?PHP echo $link;?>'><?PHP echo $letter;?></a> </li>
	<?PHP
	}
	?>
	
	<li> <a href='<?PHP echo $all;?>'>Everything (Slow)</a> </li>

</ul>




</div>


<div class="datafootbg"></div></div>

<script type="text/javascript" charset="utf-8">
	$(function() {
	$(".add_music").click(function() {

	var commentContainer = $(this).parent().parent();

	var id = $(this).attr("name");

	var z = id.split("/");
	
	var add_val='<tr id="listItem_'+z[0]+'"><td>0</td>'+'<td>'+z[2]+'</td>'+'<td>'+z[3]+'</td>'+'<td>'+z[4]+'</td>'+'<td>'+z[5]+'</td>'+'<td>No Delete</td><td class="handle">Move</td></tr>';
	var string = 'id='+ id ;

		//var answer = confirm("Add this item?")
	            if (true){
	                $.ajax({
					   type: "POST",
					   url: "m/music/a_add_music.php",
					   data: string,
					   cache: false,
						success: function(html){
					
						$('#media_table tr:last').after(add_val);
						    $("#results").html(html);

						  }
					  

					 });
					
	            }
	            else{
	                return false;
	            };
				return false;
		});
	});
</script>
